package com.example.thegreatwall.controller;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.example.thegreatwall.common.R;
import com.example.thegreatwall.entity.Feedback;
import com.example.thegreatwall.mapper.FeedbackMapper;
import com.example.thegreatwall.service.FeedbackService;
import lombok.Data;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.List;
@RequestMapping("/feedback")
@CrossOrigin(origins = "*") //无论什么源都可以访问  不写这个不允许跨域
@RestController
public class FeedbackController{
    @Autowired
    private FeedbackService feedbackService;

    @PostMapping("/addFeedback")
    public R addFeedback(@RequestBody Feedback feedback){
        Date date = new Date();
        feedback.setFeedCode("FD"+date.getTime());
        boolean save = feedbackService.save(feedback);
        System.out.println(feedback);
        if (save){
            return new R().addDate("msg","提交成功");
        }else {
            return new R().addDate("msg","提交失败");
        }
    }

    @GetMapping("/getFeedback")
    public R getFeedback(){
        List<Feedback> feedbackList = feedbackService.list();
        return new R().addDate("list",feedbackList);
    }

}